<template>
  <div>
    <van-nav-bar
      :title="$route.meta.title"
      left-text="返回"
      left-arrow
      :fixed="true"
      :placeholder="true"
      @click-left="$router.go(-1)"
      :right-text="auditBtn"
      @click-right="editApply()"
    />
    <div>
      <div class="headerbox">
        <div class="header_top" :style="{ width: columns.length * 3 + 'rem' }">
          <div
            class="header_item"
            v-for="(item, index) in columns"
            :key="index"
            @click="handleClick(index)"
            :class="tabIndex == index ? 'active' : ''"
          >
            <div class="txt">{{ item.number }}</div>
            <div class="txt1">{{ item.bizDate }}</div>
          </div>
        </div>
      </div>

      <div class="carInfo">
        <div class="carInfo_title">申请信息</div>
        <div class="carInfo_item">申请单号：{{ dataSource.billNumber }}</div>
        <div class="carInfo_item">作帐日期：{{ dataSource.bizDate }}</div>
        <div class="carInfo_item">单据状态：{{ dataSource.billStatus }}</div>
        <div class="carInfo_item">品牌：{{ dataSource.brand }}</div>
        <div class="carInfo_item">展厅：{{ dataSource.showOrgName }}</div>
        <div class="carInfo_item">开票公司：{{ dataSource.signCompany }}</div>
        <div class="carInfo_item">乙方买受人：{{ dataSource.carbuyer }}</div>
        <div class="carInfo_item">
          发票客户类型：{{ dataSource.customerType }}
        </div>
        <div class="carInfo_item">客户：{{ dataSource.customerName }}</div>
        <div class="carInfo_item">车主类型：{{ dataSource.cusType }}</div>
        <div class="carInfo_item">备注：{{ dataSource.remark }}</div>
      </div>

      <div class="carInfo">
        <div class="carInfo_title">车辆信息</div>
        <div class="carInfo_item">车架号：{{ dataSource.vinCode }}</div>
        <div class="carInfo_item">车型：{{ dataSource.carModel }}</div>
        <div class="carInfo_item">属性：{{ dataSource.property }}</div>
        <div class="carInfo_item">
          车辆售价（含佣金）：{{ dataSource.carSalePrice }}
        </div>
        <div class="carInfo_item">
          车辆售价不含税额：{{ dataSource.carSaleNoTaxPrice }}
        </div>
        <div class="carInfo_item">精品售价：{{ dataSource.qualityPrice }}</div>
        <div class="carInfo_item">
          精品售价不含税额：{{ dataSource.qualityNoTaxPrice }}
        </div>
        <div class="carInfo_item">
          精品指导价：{{ dataSource.qualityGuidePrice }}
        </div>
      </div>

      <div class="carInfo">
        <div class="carInfo_title">发票信息</div>
        <div class="tableData">
          <table>
            <tr>
              <th>发票号码</th>
              <th>发票日期</th>
              <th>含税金额</th>
              <th>税率</th>
              <th>不含税金额</th>
              <th>增值税额</th>
            </tr>
            <tr
              v-for="(item, index) in dataSource.invoiceInvoiceEntry"
              v-bind:key="index"
            >
              <td>{{ item.invoiceNo }}</td>
              <td>{{ item.invoiceDate }}</td>
              <td>{{ item.totalAmount }}</td>
              <td>{{ item.taxRate }}</td>
              <td>{{ item.Amount }}</td>
              <td>{{ item.taxAmount }}</td>
            </tr>
          </table>
        </div>
      </div>

      <div class="goBack" @click="goBack">返回</div>
      <!-- 审核情况 -->
      <AuditRecord
        :visible="auditVisible"
        :billId="dataSource.billId ? dataSource.billId : detailId"
        @close="auditVisible = false"
      ></AuditRecord>
    </div>
  </div>
</template>

<script>
import sellManageApi from "@/api/sellManageApi";
import AuditRecord from "@/components/AuditRecord";
export default {
  components: {
    AuditRecord,
  },
  data() {
    return {
      active: "",
      detailId: "", // 当前单据ID
      orderId: "", // 当前合同订单ID
      desBosType: "", // 单据类型 desBosType
      columns: [],
      tabIndex: 0,
      dataSource: {
        billId: "", //单据Id
        billNumber: "", //单据编号
        bizDate: "", //做账日期
        billStatus: "", //单据状态
        brand: "", //所属品牌
        showOrgName: "", //所属展厅
        signCompany: "", //开票公司
        signCompanyId: "", //开票公司
        customerName: "", //客户
        carbuyer: "", //乙方买受人
        carSalePrice: "", //车辆售价含佣金
        carSaleNoTaxPrice: "", //车辆售价不含税额
        qualityPrice: "", //精品售价
        qualityNoTaxPrice: "", //精品售价不含税额
        qualityGuidePrice: "", //精品指导价
        customerType: "", //发票客户类型
        cusType: "", //车主类型
        remark: "", //备注
        apInvoiceEntry: "", //分录信息
        invoiceInvoiceEntry: "", //分录信息
        purNo: "", //销售合同号
        vinCode: "", //车架号
        property: "", //属性
        carModel: "", //车型
      },
      auditBtn: "",
      auditVisible: false,
    };
  },
  mounted() {
    if (this.$route.query) {
      this.detailId = this.$route.query.billId;
      this.orderId = this.$route.query.orderId;
      this.desBosType = this.$route.query.desBosType;
      console.log(this.detailId);
      console.log(this.orderId);
      console.log(this.desBosType);
      this.getList(this.orderId);
    }
  },
  methods: {
    getDetail() {
      sellManageApi
        .secondHandCarFacade({
          method: "getSaleInvoiceDataById", //固定值
          billId: this.columns[this.tabIndex].billId, //单据Id，必填，String
        })
        .then((res) => {
          if (res.code == 1) {
            this.dataSource = res.data;
            if (this.dataSource.billStatus != "保存") {
              this.auditBtn = "审批情况";
            }
          }
        });
    },

    getList() {
      // 根据类型ID获取单据列表
      sellManageApi
        .secondHandCarFacade({
          method: "getDestInfoBySourceIdAndDestBosType", //固定值
          userId: "", //用户ID，必填，String
          orgId: "", //登录组织Id，必填，String
          billId: this.orderId, //单据Id，必填，String
          desBosType: this.desBosType,
        })
        .then((res) => {
          if (res.code == 1) {
            if (res.data.length >= 1) {
              this.columns = res.data;
              this.getDetail();
            } else {
              this.$toast.fail("暂无该单据");
            }
          } else {
            this.$toast.fail("暂无该单据");
          }
        });
    },
    handleClick(index) {
      this.tabIndex = index;
      this.getDetail();
    },
    goBack() {
      this.$router.go(-1);
    },
    editApply() {
      this.auditVisible = true;
    },
  },
};
</script>
<style lang="less" scoped>
.headerbox {
  width: 100%;
  overflow-x: auto;
  &::-webkit-scrollbar {
    display: none;
  }
}
.header_top {
  display: flex;
  align-self: center;
  padding: 0.2rem;
  overflow-x: auto;
  // width: 12rem;
  .header_item {
    width: 3rem;
    background: #fff;
    padding: 0.2rem 0.3rem;
    font-size: 0.28rem;
    border-radius: 5px;
    margin-right: 0.2rem;
    .txt {
      margin-bottom: 0.1rem;
    }
    &.active {
      border: 1px solid #ccc;
      box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
    }
  }
}
.carInfo {
  padding: 0.2rem;
  background: #fff;
  margin-bottom: 0.2rem;
  .source {
    padding-left: 0 !important;
    margin-bottom: 0.2rem;
    justify-content: space-between;

    .source_txt {
      font-size: 0.32rem;
    }
  }

  .carInfo_No {
    margin-bottom: 0.3rem;
    .carInfo_No_item {
      border-right: 1px solid #ccc;
      padding-right: 0.1rem;
      margin-right: 0.1rem;
      font-size: 0.32rem;
      color: #333;
      &:last-child {
        border: none;
      }
    }
  }
  .carInfo_item {
    font-size: 0.32rem;
    margin-bottom: 0.1rem;
    color: #333;
    .carInfo_item_price {
      width: 50%;
    }
  }
  .carInfo_title {
    font-size: 0.32rem;
    color: #333;
    margin-bottom: 0.2rem;
    font-weight: bold;
  }
}
.goBack {
  width: 80%;
  background: #2381e6;
  color: #fff;
  font-size: 0.32rem;
  margin: auto;
  border-radius: 5px;
  padding: 0.2rem;
  text-align: center;
  margin-bottom: 0.5rem;
}
.tableData {
  width: 100%;
  margin: auto;
  border-collapse: collapse;
  text-align: center;
  table {
    width: 100%;
    font-size: 0.32rem;
  }
  .tab_item {
    background: #f1f1f1;
  }
  tr {
    th {
      font-size: 0.32rem;
      border: 1px solid #ccc;
      padding: 0.2rem 0;
      background: #409eff;
      color: #fff;
    }
    td {
      padding: 0.1rem 0;
      border: 1px solid #ccc;
      font-size: 0.32rem;
    }
  }
}
</style>
